// ============================================================================
//
// Copyright (C) 2006-2008 Dengues
//
// Google Group: http://groups.google.com/group/dengues
//
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.reports.editor.design.parts;

import java.beans.PropertyChangeEvent;
import java.util.List;

import org.dengues.reports.editor.design.figures.ReportTableColumnFigure;
import org.dengues.reports.editor.design.models.RepTableColumnDiagram;
import org.dengues.reports.editor.design.policies.ReportTableFlowLayoutEditPolicy;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPolicy;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-8-20 qiang.zhang $
 * 
 */
public class RepTableColmnEditPart extends ReportElementEditPart {

    private ReportTableColumnFigure columnFigure;

    private RepTableColumnDiagram columnDiagram;

    /**
     * Qiang.Zhang.Adolf@gmail.com ReportTableColmnEditPart constructor comment.
     * 
     * @param model
     */
    public RepTableColmnEditPart(Object model) {
        super(model);
        this.columnDiagram = (RepTableColumnDiagram) model;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.reports.editor.design.parts.ReportElementEditPart#createEditPolicies()
     */
    @Override
    protected void createEditPolicies() {
        installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReportTableFlowLayoutEditPolicy());
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren()
     */
    @Override
    protected List getModelChildren() {
        return columnDiagram.getRepTableCells();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.reports.editor.design.parts.ReportElementEditPart#refreshFigure()
     */
    @Override
    public void refreshFigure() {
        Dimension preferredSize = ((RepTableEditPart) getParent()).getFigure().getPreferredSize();

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
     */
    @Override
    protected IFigure createFigure() {
        columnFigure = new ReportTableColumnFigure();
        return columnFigure;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
     */
    public void propertyChange(PropertyChangeEvent evt) {
        String propertyName = evt.getPropertyName();
        if (RepTableColumnDiagram.PROP_TABLE_CELLS.equals(propertyName)) {
            refreshChildren();
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getContentPane()
     */
    @Override
    public IFigure getContentPane() {
        return columnFigure.getChildrenFigure();
    }
}
